package it.traveldreamWeb.shared;

import it.traveldream.beans.HotelManagerInterface;
import it.traveldream.beans.TransportMeanManagerInterface;
import it.traveldream.dto.DepartureDTO;
import it.traveldream.dto.HotelDTO.HotelRoomType;
import it.traveldream.dto.LocationDTO;
import it.traveldream.utils.CalendarUtils.WeekDay;
import it.traveldreamWeb.employee.DepartureConverter;

import java.util.Arrays;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.model.SelectItem;

@ManagedBean(name="applicationDataBean")
@ApplicationScoped
public class ApplicationDataBean {

	private List<LocationDTO> locations;
	private List<DepartureDTO> departures;
	private List<String> meanTypes;
	
	@EJB
	private TransportMeanManagerInterface meanManager;
	@EJB
	private HotelManagerInterface hotelManager;
	
	@PostConstruct
	private void init(){
		this.locations = this.meanManager.getLocations();
		this.departures = this.meanManager.getDepartures();
		this.meanTypes = this.meanManager.getMeanTypes();
		
		LocationConverter.init(this.locations);
		DepartureConverter.init(this.departures);
	}
	
	public List<LocationDTO> getLocations() {
		return this.locations;
	}
	public void setLocations(List<LocationDTO> locations) {
		this.locations = locations;
	}
	public List<DepartureDTO> getDepartures() {
		return this.departures;
	}
	public void setDepartures(List<DepartureDTO> departures) {
		this.departures = departures;
	}
	public List<String> getMeanTypes() {
		return this.meanTypes;
	}
	public void setMeanTypes(List<String> meanTypes) {
		this.meanTypes = meanTypes;
	}
	
	public List<HotelRoomType> getRoomTypes() {
		return Arrays.asList(HotelRoomType.values());
	}
	
	public SelectItem[] getWeekDays(){
		SelectItem[] items = new SelectItem[WeekDay.values().length];
	    int i = 0;
	    for(WeekDay g: WeekDay.values()) {
	    	items[i++] = new SelectItem(g, g.toString());
	    }
	    return items;
	}
}
